#  ______     ______     ______     ______     ______   __     ______     ______
# /\  ___\   /\  == \   /\  ___\   /\  __ \   /\__  _\ /\ \   /\___  \   /\  ___\
# \ \ \____  \ \  __<   \ \  __\   \ \  __ \  \/_/\ \/ \ \ \  \/_/  /__  \ \  __\
#  \ \_____\  \ \_\ \_\  \ \_____\  \ \_\ \_\    \ \_\  \ \_\   /\_____\  \ \_____\
#   \/_____/   \/_/ /_/   \/_____/   \/_/\/_/     \/_/   \/_/   \/_____/   \/_____/

# Code is licensed under CC-BY-NC-ND 4.0 unless otherwise specified.
# https://creativecommons.org/licenses/by-nc-nd/4.0/
# You CANNOT edit this file without direct permission from the author.
# You can redistribute this file without any changes.

# meta developer: @creaz_mods
# scope: hikka_min 1.6.2
# requires: logging

import logging

from hikkatl.types import Message

from .. import loader, utils


@loader.tds
class logflood(loader.Module):
    """Floods in logs."""

    strings = {
        "name": "logflood",
        "no_args": (
            "<emoji document_id=5260342697075416641>❌</emoji><b> You did not specify"
            " arguments"
        ),
        "done": "<emoji document_id=5784891605601225888>🔵</emoji> Successfully!",
        "wait": "<emoji document_id=5220118571706755791>🕒</emoji> Please wait...",
    }

    strings_ru = {
        "no_args": (
            "<emoji document_id=5260342697075416641>❌</emoji><b> Вы не указали"
            " аргументы"
        ),
        "wait": "<emoji document_id=5220118571706755791>🕒</emoji> Ожидайте...",
        "done": "<emoji document_id=5784891605601225888>🔵</emoji> Успешно!",
        "_cls_doc": "Флудит в логи.",
    }

    strings_es = {
        "no_args": (
            "<emoji document_id=5260342697075416641>❌</emoji><b>No ha especificado"
            " argumentos"
        ),
        "wait": "<emoji document_id=5220118571706755791>🕒</emoji> Esperando...",
        "done": (
            "<emoji document_id=5784891605601225888>🔵</emoji> ¡Completado con éxito!"
        ),
        "_cls_doc": "Inunda los registros.",
    }

    strings_de = {
        "no_args": (
            "<emoji document_id=5260342697075416641>❌</emoji><b> Sie haben keine"
            " Argumente angegeben"
        ),
        "wait": "<emoji document_id=5220118571706755791>🕒</emoji> Warten Sie...",
        "done": "<emoji document_id=5784891605601225888>🔵</emoji> Erfolgreich!",
        "_cls_doc": "Flutet die logs.",
    }

    def __init__(self):
        self.config = loader.ModuleConfig(
            loader.ConfigValue(
                "lvl",
                "info",
                lambda: "logging level",
                validator=loader.validators.Choice(["info", "error", "warning"]),
            ),
        )

    @loader.command()
    async def lf(self, m: Message):
        """message >> count"""
        args = utils.get_args_split_by(m, ">>")

        if len(args) != 2:
            return await utils.answer(m, self.strings("no_args"))

        if self.config["lvl"] == "info":
            await utils.answer(m, self.strings("wait"))
            for i in range(int(args[1])):
                logging.info(args[0])

        if self.config["lvl"] == "error":
            await utils.answer(m, self.strings("wait"))
            for i in range(int(args[1])):
                logging.error(args[0])

        if self.config["lvl"] == "warning":
            await utils.answer(m, self.strings("wait"))
            for i in range(int(args[1])):
                logging.warning(args[0])

        await utils.answer(m, self.strings("done"))
